﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcLibrary.Repository;

namespace VietPremier.Areas.AdminCP.Controllers
{
    public class ProfileAdminController : Controller
    {
        //
        // GET: /AdminCP/ProfileAdmin/

        public ActionResult Index()
        {
            return View();
        }

        //POST: /Admin/ProfileAdmin/changeAccount
        [HttpPost]
        public JsonResult changeAccount(string username, string password)
        {

            try
            {

                dbVietPremierDataContext db = new dbVietPremierDataContext();

                var adminquery = (from p in db.EntityAdmins
                                  where p.Username == username
                                  select p).Single();


                Security ser = new Security();
                string hex = ser.GetHashPassword(password);
                adminquery.Password = hex;

                db.SubmitChanges();

                return Json(adminquery);
            }
            catch
            {
                EntityAdmin admin = new EntityAdmin();
                admin.Password = "!"; // error
                return Json(admin);
            }


        }
    }
}
